﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ue.Utility;

namespace Ue.Framework.Tests.Utilities
{
    /// <summary>
    /// VirtualPathHelper 的摘要说明
    /// </summary>
    [TestClass]
    public class VirtualPathHelperTests
    {
        [TestMethod]
        public void IsMalformedVirtualPath()
        {
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("~/a.txt"));
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("/a.txt"));

            //因为a.txt已经处于根目录，如果再通过“..”向上级目录跳转，那么它将跳出应用程序根目录，所以是无效的
            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("~/../a.txt"));
            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("/../a.txt"));

            //因为a.txt通过“..”向上级目录跳转后的结果是“~/a.txt”，它仍然在应用程序目录中，所以它是有效的
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("~/a/../a.txt"));
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("/a/../a.txt"));

            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("~/a/b/../a.txt"));
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("/a/b/../a.txt"));

            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("~/a/b/../../a.txt"));
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("/a/b/../../a.txt"));

            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("~/a/b/../../../a.txt"));
            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("/a/b/../../../a.txt"));

            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("~/../b//a.txt"));
            Assert.IsTrue(VirtualPathHelper.IsMalformedVirtualPath("/../b//a.txt"));

            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("~/a/../b//a.txt"));
            Assert.IsFalse(VirtualPathHelper.IsMalformedVirtualPath("/a/../b//a.txt"));
        }
    }
}
